import pytest
from selenium import webdriver
import time

from selenium.webdriver.common.by import By
from lianxi630.common import *

# 进行参数化，将读取的数据切割给用例
@pytest.mark.parametrize('test_case',load_test_data())
def test_login(test_case):
    print('\n',test_case)
    driver=webdriver.Edge()
    driver.maximize_window()
    driver.get('http://10.59.9.14:7003/')
    driver.find_element(By.LINK_TEXT,'登录').click()
    time.sleep(2)
    driver.find_element(By.NAME, 'username').send_keys(test_case['username'])
    driver.find_element(By.NAME, 'password').send_keys(test_case['password'])
    time.sleep(10)
    driver.find_element(By.CLASS_NAME, 'finish-btn').click()
    time.sleep(2)
    if test_case['case_id']=='case_001':
        dy=driver.find_element(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a').text
        print('登录成功后断言:',dy)
    else:
        dy=driver.find_element(By.XPATH,'/html/body/div[4]/div/div[1]/div[1]/span[1]').text
        print('登录失败后断言',dy)
    driver.quit()
    time.sleep(2)
    try:
        point=driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[2]/span[1]').text
        print(point)
    except Exception as e:
        print("对余额断言 异常")